package asteroids.model.statements;

import java.util.HashMap;

import asteroids.model.*;
import asteroids.model.expressions.*;

/**
 * A class that represents all the ExpressionStatements
 * An expressionstatement is a statement with an expression
 * 
 * @version 1.0
 * 
 * @author	Thijs Peirelinck & Wouter Parys
 *
 */
public abstract class ExpressionStatement implements S{
        
        private final E originalExpression;
        
        public ExpressionStatement(E e) {
                this.originalExpression = e;
        }
        
        public E getExpression() {
                return originalExpression;
        }
        
        public E getValidatedExpressionCopy(E expr, HashMap<String, E> variables) {
                if (expr instanceof Variable) {
                        if (variables.get(((Variable)expr).getValue()).getReturnType().equals("double")) {
                                return new DoubleLiteral(((Double)variables.get(((Variable)expr).getValue()).getValue()));
                        }
                        
                        else if((variables.get(((Variable)expr).getValue()).getReturnType().equals("boolean"))){
                                return new BooleanLiteral(((Boolean)variables.get(((Variable)expr).getValue()).getValue()));
                        }
                        else {
                                assert (variables.get(((Variable)expr).getValue()).getReturnType().equals("entity"));
                                return new EntityLiteral(((FlyingObject)variables.get(((Variable)expr).getValue()).getValue()));
                        }
                }
                else {
                        E exprCopy = expr.createCopy();
                        exprCopy.validate(variables);
                        return exprCopy;
                }
        }
}